﻿using FireChat.Client.Session.Receiver;
using FireChat.Share.Web.Actions;
using FireChat.Share.Web.Model.Enums;
using FireChat.Share.Web.Model.Query.Account;
using FireChat.Share.Web.Package;

namespace FireChat.Client.Session.Manager;


/// <summary>
/// 账户管理类
/// </summary>
internal static class AccountManager
{
    /// <summary>
    /// 登录
    /// </summary>
    public static async Task<IResponse> LoginAsync(this ClientCore client, string username, string password)
    {
        LoginQuery data = new()
        {
            Username = username,
            Password = password,
        };

        var package = ServertActions.Login.CreatePackage(data);
        return await client.SendReceiveAsync(package);
    }

    /// <summary>
    /// 注册
    /// </summary>
    public static async Task<IResponse> Register(this ClientCore client, string username, string password)
    {
        RegisterQuery data = new()
        {
            Username = username,
            Password = password,
        };

        var package = ServertActions.Register.CreatePackage(data);
        return await client.SendReceiveAsync(package);
    }

    /// <summary>
    /// 登出
    /// </summary>
    public static async Task<IResponse> LogoutAsync(this ClientCore client)
    {
        var package = ServertActions.Logout.CreatePackage();
        return await client.SendReceiveAsync(package);
    }
}